<template>
  <el-inline-form
    ref="customInlineFormRef"
    label-size="small"
    :model="formInline"
    :use-option-default-reset-func="false"
    @do-search="handleSearch"
    @do-reset="handleReset"
  >
    <el-inline-form-item v-model="formInline.age" label="年龄">
      <el-input v-model="formInline.age" placeholder="年龄" clearable />
    </el-inline-form-item>
    <template v-if="isShow">
      <el-inline-form-item label="申请人">
        <el-input v-model="formInline.user" placeholder="申请人" clearable />
      </el-inline-form-item>
      <el-inline-form-item label="订单编号">
        <el-input
          v-model="formInline.orderId"
          placeholder="订单编号"
          clearable
        />
      </el-inline-form-item>
    </template>
    <el-inline-form-item label="位置">
      <el-select v-model="formInline.region" placeholder="位置" clearable>
        <el-option label="Zone one" value="shanghai" />
        <el-option label="Zone two" value="beijing" />
      </el-select>
    </el-inline-form-item>
    <el-inline-form-item label="激活时间">
      <el-date-picker
        v-model="formInline.date"
        type="date"
        placeholder="激活时间"
        clearable
      />
    </el-inline-form-item>

    <el-inline-form-item label="级联">
      <el-cascader
        v-model="formInline.cascaders"
        :options="options"
        placeholder="级联选择器"
        clearable
      />
    </el-inline-form-item>
  </el-inline-form>
</template>

<script lang="ts" setup>
import { onMounted, reactive, ref } from 'vue'
import type { FormInstance } from 'hive-plus'
const formInline = reactive({
  user: '',
  region: '',
  date: '',
  age: '',
  orderId: '',
  cascaders: [],
})

const options = [
  {
    value: 'guide',
    label: 'Guide',
    children: [
      {
        value: 'disciplines',
        label: 'Disciplines',
        children: [
          {
            value: 'consistency',
            label: 'Consistency',
          },
          {
            value: 'feedback',
            label: 'Feedback',
          },
          {
            value: 'efficiency',
            label: 'Efficiency',
          },
          {
            value: 'controllability',
            label: 'Controllability',
          },
        ],
      },
      {
        value: 'navigation',
        label: 'Navigation',
        children: [
          {
            value: 'side nav',
            label: 'Side Navigation',
          },
          {
            value: 'top nav',
            label: 'Top Navigation',
          },
        ],
      },
    ],
  },
  {
    value: 'component',
    label: 'Component',
    children: [
      {
        value: 'basic',
        label: 'Basic',
        children: [
          {
            value: 'layout',
            label: 'Layout',
          },
          {
            value: 'color',
            label: 'Color',
          },
          {
            value: 'typography',
            label: 'Typography',
          },
          {
            value: 'icon',
            label: 'Icon',
          },
          {
            value: 'button',
            label: 'Button',
          },
        ],
      },
      {
        value: 'form',
        label: 'Form',
        children: [
          {
            value: 'radio',
            label: 'Radio',
          },
          {
            value: 'checkbox',
            label: 'Checkbox',
          },
          {
            value: 'input',
            label: 'Input',
          },
          {
            value: 'input-number',
            label: 'InputNumber',
          },
          {
            value: 'select',
            label: 'Select',
          },
          {
            value: 'cascader',
            label: 'Cascader',
          },
          {
            value: 'switch',
            label: 'Switch',
          },
          {
            value: 'slider',
            label: 'Slider',
          },
          {
            value: 'time-picker',
            label: 'TimePicker',
          },
          {
            value: 'date-picker',
            label: 'DatePicker',
          },
          {
            value: 'datetime-picker',
            label: 'DateTimePicker',
          },
          {
            value: 'upload',
            label: 'Upload',
          },
          {
            value: 'rate',
            label: 'Rate',
          },
          {
            value: 'form',
            label: 'Form',
          },
        ],
      },
      {
        value: 'data',
        label: 'Data',
        children: [
          {
            value: 'table',
            label: 'Table',
          },
          {
            value: 'tag',
            label: 'Tag',
          },
          {
            value: 'progress',
            label: 'Progress',
          },
          {
            value: 'tree',
            label: 'Tree',
          },
          {
            value: 'pagination',
            label: 'Pagination',
          },
          {
            value: 'badge',
            label: 'Badge',
          },
        ],
      },
      {
        value: 'notice',
        label: 'Notice',
        children: [
          {
            value: 'alert',
            label: 'Alert',
          },
          {
            value: 'loading',
            label: 'Loading',
          },
          {
            value: 'message',
            label: 'Message',
          },
          {
            value: 'message-box',
            label: 'MessageBox',
          },
          {
            value: 'notification',
            label: 'Notification',
          },
        ],
      },
      {
        value: 'navigation',
        label: 'Navigation',
        children: [
          {
            value: 'menu',
            label: 'Menu',
          },
          {
            value: 'tabs',
            label: 'Tabs',
          },
          {
            value: 'breadcrumb',
            label: 'Breadcrumb',
          },
          {
            value: 'dropdown',
            label: 'Dropdown',
          },
          {
            value: 'steps',
            label: 'Steps',
          },
        ],
      },
      {
        value: 'others',
        label: 'Others',
        children: [
          {
            value: 'dialog',
            label: 'Dialog',
          },
          {
            value: 'tooltip',
            label: 'Tooltip',
          },
          {
            value: 'popover',
            label: 'Popover',
          },
          {
            value: 'card',
            label: 'Card',
          },
          {
            value: 'carousel',
            label: 'Carousel',
          },
          {
            value: 'collapse',
            label: 'Collapse',
          },
        ],
      },
    ],
  },
  {
    value: 'resource',
    label: 'Resource',
    children: [
      {
        value: 'axure',
        label: 'Axure Components',
      },
      {
        value: 'sketch',
        label: 'Sketch Templates',
      },
      {
        value: 'docs',
        label: 'Design Documentation',
      },
    ],
  },
]

const isShow = ref(true)
const customInlineFormRef = ref<FormInstance | undefined>()
onMounted(() => {
  setTimeout(() => {
    isShow.value = false
    customInlineFormRef.value?.update() // update form
  }, 2000)
})

const handleSearch = () => {
  console.log('doSearchHandle::', formInline)
}

const handleReset = () => {
  console.log('doResetHandle：：这里需要主动将表单内容情况，再实现后续逻辑')

  formInline.user = ''
  formInline.orderId = ''
  formInline.region = ''
  formInline.date = ''
  formInline.age = ''
  formInline.cascaders = []
}
</script>
